package com.miyake.dsp.converter.ui;

import com.miyake.dsp.converter.LimiterSetting;
import com.miyake.dsp.ui.DspTextField;
import com.miyake.dsp.ui.DspWidget;
import com.miyake.dsp.ui.DspWidget.DspWidgetHandler;

public class LimiterSettingUI extends DspWidget {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4556846961892964536L;
	private LimiterSetting setting;

	public LimiterSettingUI(LimiterSetting setting) {
		this.setting = setting;
		
		createMin();
		createMax();
	}

	private void createMax() {
		DspTextField text = new DspTextField("Max");
		text.setValue(String.valueOf(setting.getMax()));
		this.add(text);
		
		text.addHandler(new DspWidgetHandler() {
			@Override
			public void onChange(String value) {
				setting.setMax(Double.valueOf(value));
				fireChange(value);
			}
		});	
	}

	private void createMin() {
		DspTextField text = new DspTextField("Min");
		text.setValue(String.valueOf(setting.getMin()));
		this.add(text);
		
		text.addHandler(new DspWidgetHandler() {
			@Override
			public void onChange(String value) {
				setting.setMin(Double.valueOf(value));
				fireChange(value);
			}
		});	
	}
}
